package com.moxiao.yfjh.module.activity.common;

import com.moxiao.yfjh.module.activity.controller.admin.activityEnroll.vo.ActivityEnrollRespVO;
import com.moxiao.yfjh.module.activity.controller.admin.activityInfo.vo.ActivityInfoRespVO;
import com.moxiao.yfjh.module.activity.controller.app.vo.AppWriteOffVO;
import com.moxiao.yfjh.module.blind.common.NotifyMessageEnum;
import com.moxiao.yfjh.module.blind.controller.admin.notifymessage.vo.BlindNotifyMessageCreateReqVO;
import com.moxiao.yfjh.module.blind.service.notifymessage.BlindNotifyMessageService;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;

/**
 * @version 1.0
 * @Author zhk
 * @Date 2024/2/20 17:12
 **/
@Component
public class ActivityNotifyMessageUtils {


    @Resource
    private BlindNotifyMessageService blindNotifyMessageService;

    /**
     * 活动通知：活动被发布人关闭通知
     *
     * @param createReqVO
     */
    public void createActivityCleanMessage(ActivityEnrollRespVO createReqVO) {
        BlindNotifyMessageCreateReqVO blindNotifyMessageCreateReqVO = new BlindNotifyMessageCreateReqVO();
        blindNotifyMessageCreateReqVO.setUserId(String.valueOf(createReqVO.getUserId()));
        blindNotifyMessageCreateReqVO.setMessageType(NotifyMessageEnum.ACTIVITY_SYSTEM_CLOSED.getType());

        String context = NotifyMessageEnum.ACTIVITY_FOUNDER_CLOSED.getContext();
        String format = String.format(context, createReqVO.getActivityName());
        blindNotifyMessageCreateReqVO.setContent(format);

        String jumpUrl = NotifyMessageEnum.ACTIVITY_SYSTEM_CLOSED.getJumpUrl();
        blindNotifyMessageCreateReqVO.setJumpUrl(String.format(jumpUrl, createReqVO.getActivityId()));
        blindNotifyMessageCreateReqVO.setReadStatus(0);
        blindNotifyMessageCreateReqVO.setStatus((byte) 4);
        blindNotifyMessageCreateReqVO.setTitle("活动通知");
        blindNotifyMessageService.createNotifyMessage(blindNotifyMessageCreateReqVO);
    }

    /**
     * 活动通知：活动被创建人关闭后参与人收到通知
     *
     * @param enrollRespVO
     */
    public void createActivityEnrollMessage(ActivityEnrollRespVO enrollRespVO) {
        BlindNotifyMessageCreateReqVO blindNotifyMessageCreateReqVO = new BlindNotifyMessageCreateReqVO();
        blindNotifyMessageCreateReqVO.setUserId(String.valueOf(enrollRespVO.getUserId()));
        blindNotifyMessageCreateReqVO.setMessageType(NotifyMessageEnum.ACTIVITY_FOUNDER_CLOSED.getType());

        String context = NotifyMessageEnum.ACTIVITY_FOUNDER_CLOSED.getContext();
        String format = String.format(context, enrollRespVO.getActivityName());
        blindNotifyMessageCreateReqVO.setContent(format);

        String jumpUrl = NotifyMessageEnum.ACTIVITY_FOUNDER_CLOSED.getJumpUrl();
        blindNotifyMessageCreateReqVO.setJumpUrl(String.format(jumpUrl, enrollRespVO.getActivityId()));

        blindNotifyMessageCreateReqVO.setReadStatus(0);
        blindNotifyMessageCreateReqVO.setStatus((byte) 4);
        blindNotifyMessageCreateReqVO.setTitle("活动通知");
        blindNotifyMessageService.createNotifyMessage(blindNotifyMessageCreateReqVO);
    }

    /**
     * 活动通知：活动被系统关闭后参与人收到通知
     */
    public void createActivitySystemMessage(ActivityEnrollRespVO enrollRespVO) {
        BlindNotifyMessageCreateReqVO blindNotifyMessageCreateReqVO = new BlindNotifyMessageCreateReqVO();
        blindNotifyMessageCreateReqVO.setUserId(String.valueOf(enrollRespVO.getUserId()));
        blindNotifyMessageCreateReqVO.setMessageType(NotifyMessageEnum.ACTIVITY_SYSTEM_CLOSED.getType());

        String context = NotifyMessageEnum.ACTIVITY_SYSTEM_CLOSED.getContext();
        String format = String.format(context, enrollRespVO.getActivityName());
        blindNotifyMessageCreateReqVO.setContent(format);

        String jumpUrl = NotifyMessageEnum.ACTIVITY_SYSTEM_CLOSED.getJumpUrl();
        blindNotifyMessageCreateReqVO.setJumpUrl(String.format(jumpUrl, enrollRespVO.getActivityId()));

        blindNotifyMessageCreateReqVO.setReadStatus(0);
        blindNotifyMessageCreateReqVO.setStatus((byte) 4);
        blindNotifyMessageCreateReqVO.setTitle("活动通知");
        blindNotifyMessageService.createNotifyMessage(blindNotifyMessageCreateReqVO);
    }

    /**
     * 活动通知：距离活动开始时间前一天十点发送，明天的活动就今天发通知提醒
     */

    public void createActivityStartMessage(ActivityEnrollRespVO enrollRespVO) {

        BlindNotifyMessageCreateReqVO blindNotifyMessageCreateReqVO = new BlindNotifyMessageCreateReqVO();
        blindNotifyMessageCreateReqVO.setUserId(String.valueOf(enrollRespVO.getUserId()));
        blindNotifyMessageCreateReqVO.setMessageType(NotifyMessageEnum.ACTIVITY_PLAYERS_BEGINS.getType());

        String context = NotifyMessageEnum.ACTIVITY_PLAYERS_BEGINS.getContext();
        String format = String.format(context, enrollRespVO.getActivityName(), enrollRespVO.getActiveDate());
        blindNotifyMessageCreateReqVO.setContent(format);

        String jumpUrl = NotifyMessageEnum.ACTIVITY_PLAYERS_BEGINS.getJumpUrl();
        blindNotifyMessageCreateReqVO.setJumpUrl(String.format(jumpUrl, enrollRespVO.getActivityId()));

        blindNotifyMessageCreateReqVO.setReadStatus(0);
        blindNotifyMessageCreateReqVO.setStatus((byte) 4);
        blindNotifyMessageCreateReqVO.setTitle("活动通知");
        blindNotifyMessageService.createNotifyMessage(blindNotifyMessageCreateReqVO);
    }


    /**
     * 活动通知：活动审核通知
     */
    public void createActivityInfoAuditMessage(ActivityInfoRespVO respVO, Integer type) {

        BlindNotifyMessageCreateReqVO blindNotifyMessageCreateReqVO = new BlindNotifyMessageCreateReqVO();
        blindNotifyMessageCreateReqVO.setUserId(String.valueOf(respVO.getHeadUserId()));
        if (type == 1) {
            blindNotifyMessageCreateReqVO.setMessageType(NotifyMessageEnum.ACTIVITY_APPROVED_PASS.getType());
            String context = NotifyMessageEnum.ACTIVITY_APPROVED_PASS.getContext();
            String format = String.format(context, respVO.getName());
            blindNotifyMessageCreateReqVO.setContent(format);
            String jumpUrl = NotifyMessageEnum.ACTIVITY_APPROVED_PASS.getJumpUrl();
            blindNotifyMessageCreateReqVO.setJumpUrl(String.format(jumpUrl, respVO.getId()));
        } else {
            blindNotifyMessageCreateReqVO.setMessageType(NotifyMessageEnum.ACTIVITY_APPROVED_NO_PASS.getType());
            String context = NotifyMessageEnum.ACTIVITY_APPROVED_NO_PASS.getContext();
            String format = String.format(context, respVO.getName());
            blindNotifyMessageCreateReqVO.setContent(format);
            String jumpUrl = NotifyMessageEnum.ACTIVITY_APPROVED_NO_PASS.getJumpUrl();
            blindNotifyMessageCreateReqVO.setJumpUrl(String.format(jumpUrl, respVO.getId()));
        }
        blindNotifyMessageCreateReqVO.setReadStatus(0);
        blindNotifyMessageCreateReqVO.setStatus((byte) 4);
        blindNotifyMessageCreateReqVO.setTitle("活动通知");
        blindNotifyMessageService.createNotifyMessage(blindNotifyMessageCreateReqVO);
    }

    /**
     * 活动通知：（创建者/参与者）活动被系统关闭后参与人收到通知（创建人收到通知）
     */
    public void createActivityCreateCleanMessage(ActivityEnrollRespVO enrollRespVO, Integer type) {

        BlindNotifyMessageCreateReqVO blindNotifyMessageCreateReqVO = new BlindNotifyMessageCreateReqVO();
        blindNotifyMessageCreateReqVO.setUserId(String.valueOf(enrollRespVO.getUserId()));
        if (type == 1) {
            blindNotifyMessageCreateReqVO.setMessageType(NotifyMessageEnum.ACTIVITY_CREATOR_CLOSED.getType());
            String context = NotifyMessageEnum.ACTIVITY_CREATOR_CLOSED.getContext();
            String format = String.format(context, enrollRespVO.getActivityName());
            blindNotifyMessageCreateReqVO.setContent(format);
            String jumpUrl = NotifyMessageEnum.ACTIVITY_CREATOR_CLOSED.getJumpUrl();
            blindNotifyMessageCreateReqVO.setJumpUrl(String.format(jumpUrl, enrollRespVO.getActivityId()));
        } else {
            blindNotifyMessageCreateReqVO.setMessageType(NotifyMessageEnum.ACTIVITY_SYSTEM_CLOSED.getType());
            String context = NotifyMessageEnum.ACTIVITY_SYSTEM_CLOSED.getContext();
            String format = String.format(context, enrollRespVO.getActivityName());
            blindNotifyMessageCreateReqVO.setContent(format);
            String jumpUrl = NotifyMessageEnum.ACTIVITY_SYSTEM_CLOSED.getJumpUrl();
            blindNotifyMessageCreateReqVO.setJumpUrl(String.format(jumpUrl, enrollRespVO.getActivityId()));
        }
        blindNotifyMessageCreateReqVO.setReadStatus(0);
        blindNotifyMessageCreateReqVO.setStatus((byte) 4);
        blindNotifyMessageCreateReqVO.setTitle("活动通知");
        blindNotifyMessageService.createNotifyMessage(blindNotifyMessageCreateReqVO);
    }

    /**
     * 活动通知（创建者/参与者）：距离活动开始时间前一天十点发送，明天的活动就今天发通知提醒
     */

    public void createActivityCreateStartMessage(ActivityEnrollRespVO enrollRespVO, Integer type) {

        BlindNotifyMessageCreateReqVO blindNotifyMessageCreateReqVO = new BlindNotifyMessageCreateReqVO();
        blindNotifyMessageCreateReqVO.setUserId(String.valueOf(enrollRespVO.getUserId()));
        if (type == 1) {
            blindNotifyMessageCreateReqVO.setMessageType(NotifyMessageEnum.ACTIVITY_FOUNDER_BEGINS.getType());
            String context = NotifyMessageEnum.ACTIVITY_FOUNDER_BEGINS.getContext();
            String format = String.format(context, enrollRespVO.getActivityName(), enrollRespVO.getActiveDate());
            blindNotifyMessageCreateReqVO.setContent(format);

            String jumpUrl = NotifyMessageEnum.ACTIVITY_FOUNDER_BEGINS.getJumpUrl();
            blindNotifyMessageCreateReqVO.setJumpUrl(String.format(jumpUrl, enrollRespVO.getActivityId()));
        } else {
            blindNotifyMessageCreateReqVO.setMessageType(NotifyMessageEnum.ACTIVITY_PLAYERS_BEGINS.getType());
            String context = NotifyMessageEnum.ACTIVITY_PLAYERS_BEGINS.getContext();
            String format = String.format(context, enrollRespVO.getActivityName(), enrollRespVO.getActiveDate());
            blindNotifyMessageCreateReqVO.setContent(format);
            String jumpUrl = NotifyMessageEnum.ACTIVITY_PLAYERS_BEGINS.getJumpUrl();
            blindNotifyMessageCreateReqVO.setJumpUrl(String.format(jumpUrl, enrollRespVO.getActivityId()));
        }

        blindNotifyMessageCreateReqVO.setReadStatus(0);
        blindNotifyMessageCreateReqVO.setStatus((byte) 4);
        blindNotifyMessageCreateReqVO.setTitle("活动通知");
        blindNotifyMessageService.createNotifyMessage(blindNotifyMessageCreateReqVO);
    }

    /**
     * 活动通知：活动商品核销成功
     */

    public void createVerificateMessage(AppWriteOffVO appWriteOffVO) {
        BlindNotifyMessageCreateReqVO blindNotifyMessageCreateReqVO = new BlindNotifyMessageCreateReqVO();
        blindNotifyMessageCreateReqVO.setUserId(String.valueOf(appWriteOffVO.getUserId()));
        blindNotifyMessageCreateReqVO.setMessageType(NotifyMessageEnum.ACTIVITY_VERIFICATION.getType());
        String context = NotifyMessageEnum.ACTIVITY_VERIFICATION.getContext();
        String format = String.format(context, appWriteOffVO.getName(), appWriteOffVO.getMerchantTypeName(), appWriteOffVO.getProductName());
        blindNotifyMessageCreateReqVO.setContent(format);
        String jumpUrl = NotifyMessageEnum.ACTIVITY_VERIFICATION.getJumpUrl();
        blindNotifyMessageCreateReqVO.setJumpUrl(String.format(jumpUrl, appWriteOffVO.getId()));
        blindNotifyMessageCreateReqVO.setReadStatus(0);
        blindNotifyMessageCreateReqVO.setStatus((byte) 4);
        blindNotifyMessageCreateReqVO.setTitle("活动通知");
        blindNotifyMessageService.createNotifyMessage(blindNotifyMessageCreateReqVO);
    }
}
